package com.xbs.controller.admin;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.LimitEntity;
import com.xbs.service.content.LimitAdminService;
@WebServlet("/admin/index")

public class BackStage extends BaseServlet{
	//权限服务层
	private LimitAdminService las;
	//接受拥有的权限集合
	private List<LimitEntity> le;
	public BackStage() {
		las = new LimitAdminService();
		le = new ArrayList<LimitEntity>();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req,resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String role = req.getSession().getAttribute("erole").toString();
		
		int role_id = las.selRoleId(role);
		//根据角色获取该用户的权限集合
		le = las.selLimit(role_id);
		String str="";
		for(LimitEntity li:le){
			if(Integer.parseInt(li.getLimitparent())==0){
				str+="<li>"
						+ "<a href=\"javascript:void(0);\" class=\"block menu-triggle relative\" role=\"dropdown-trigger\">"
						+ "<i class=\"fa fa-cog\" style=\"margin-right:10px;\"></i>"+li.getLimitname()+"<i class=\"triangle\"></i></a>"
						+"<ul class=\"sub-menu hidden\">";
				for(LimitEntity lt:le){
					if(Integer.parseInt(lt.getLimitparent())==li.getLimitid()){
						str+="<li><a href=\""+lt.getLimiturl()+"\" target=\"main\">"+lt.getLimitname()+"</a></li>";
									
					}
				}
				str+="</ul>";	
			}
		}
		str+="</li>";
		System.out.println(str);
		
		req.getSession().setAttribute("str", str);

		forward("admin/mian");
	}
}
